package leetcode;

import org.junit.Test;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 2/20/2022 9:52 AM
 */
public class Test509 {


    @Test
    public void test() {
        System.out.println(fib(3));
    }


    public int fib(int n) {
        if (n == 0) return 0;
        if (n == 1) return 1;
        int p, q = 0, r = 1;
        for (int i = 2; i <= n; i++) {
            p = q;
            q = r;
            r = p + q;
        }
        return r;
    }


}
